home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / vollvers / adamaslg / ovl.src / x32play.c < prev    next >
C/C++ Source or Header  |  1998-12-18  |  3KB  |  140 lines

  1. #include "extern.h"
  2. #include <stddef.h>
  3. #include <time.h>
  4. #include <vdi.h>
  5. #include <stdio.h>
  6.  
  7. int sys;
  8. extern int tx_width, tx_height;
  9.  
  10. /* 
  11.    Initialize X32-Player plug-in.
  12.    
  13.    This function will be only called once, after loading the plug-in.
  14. */
  15. int cdecl init_ovl(int *sysinfo, BASPAG *baspag)
  16. {
  17. _BasPag = baspag;
  18. sys = sysinfo[0];                 /* 0 = Single; 1 = Mint; 2 = MagX, 3 = MultiTOS */
  19.  
  20. open_panelvwk();
  21.  
  22. Mshrink(0, baspag, 
  23.         TEXTsize(baspag) + DATAsize(baspag) + BSSsize(baspag) + sizeof(BASPAG));
  24. return TRUE;
  25. }
  26.  
  27. /* 
  28.    Release X32-Sound object.
  29.    
  30.    This function will be called on destroying an
  31.    object inside the web-page.
  32. */
  33. int cdecl release_ovl(OBJ_INFO *oinf)
  34. {
  35. if (((X32_INFO *)oinf->user)->playing)    /* Is it playing */
  36.   stop_sound(oinf);
  37.  
  38. if (oinf->user)
  39.     {
  40.     X32_INFO *x32info;
  41.     
  42.     x32info = oinf->user;
  43.     Mfree(x32info->name);                            /* Free name memory */
  44.     Mfree(x32info->data);                            /* Free data memory */
  45.     
  46.     Mfree(x32info);                                        /* Free managment structure */
  47.     oinf->user = NULL;
  48.     }
  49.   
  50. return TRUE;
  51. }
  52.  
  53. /* 
  54.    Remove X32Player plug-in.
  55.    
  56.    This function will be called only once before 
  57.    unloading the plug-in.
  58. */
  59. int cdecl exit_ovl(void)
  60. {
  61. close_panelvwk();
  62.  
  63. Mfree(_BasPag->p_env);        /* Free allocated environment */
  64. return !Mfree(_BasPag);        /* Free plug-in */
  65. }
  66.  
  67. /* 
  68.    Play sound
  69. */
  70. int cdecl execute_ovl(char *src, OBJ_INFO *oinf)
  71. {
  72. char *s;
  73. int w;
  74. long fh, length;
  75.  
  76. s = strrchr(src, '\\');
  77. if (!s) s = src; else s++;
  78. w = (int)strlen(s) * tx_width + 4;                /* Calculate text width */
  79.  
  80. if (oinf->obj_w == -1)            /* No size set ? */
  81.     oinf->obj_w = w;
  82.  
  83. if (oinf->obj_h == -1)
  84.     oinf->obj_h = 16;
  85.  
  86. w += oinf->obj_h * 2;
  87. if (w > oinf->obj_w && oinf->obj_w)                /* If it is to small and a */
  88.     oinf->obj_w = w;                                                /* width is given resize to minimum */
  89.                                                                                     /* width */
  90.                                                                                     
  91. if (tx_height > oinf->obj_h && oinf->obj_h)    /* Same for the height */
  92.     oinf->obj_h = tx_height;
  93.  
  94. if (!oinf->user)                                                    /* No user area ? */
  95.     {
  96.     X32_INFO *x32info;
  97.     
  98.     x32info = (X32_INFO *)Malloc(sizeof(X32_INFO));
  99.     oinf->user = x32info;                            /* Allocate user structure */
  100.  
  101.     x32info->name = (char *)Malloc(strlen(s) + 1);
  102.     strcpy(x32info->name, s);                    /* Copy filename */
  103.  
  104.     fh = Fopen(src, FO_READ);
  105.     if (fh > 0)                                                /* Is file opened? */
  106.         {
  107.         length = Fseek(0, (int)fh, 2);    
  108.         Fseek(0, (int)fh, 0);
  109.         x32info->data = (char *)Mxalloc(length, 0);
  110.         Fread((int)fh, length, x32info->data);        /* Load XB32 data */
  111.         Fclose((int)fh);
  112.         }    
  113.     else
  114.         x32info->data = NULL;
  115.         
  116.     x32info->button_pressed = -1;
  117.     }
  118.  
  119. /* If it should start automatically and it is not running now,
  120.      then start it. */
  121. if (oinf->started >= 0 && !((X32_INFO *)oinf->user)->playing)
  122.     start_sound(oinf);
  123.     
  124. return 1;
  125. }
  126.  
  127. /* 
  128.     Object timer function, takes care about the looping
  129. */
  130. long cdecl timer_ovl(OBJ_INFO *oinf)
  131. {
  132. if (((X32_INFO *)oinf->user)->playing && oinf->loop)
  133.     {
  134.     if (!DosoundX32((void *)-1L))
  135.         start_sound(oinf);
  136.     }
  137.  
  138. return CLK_TCK;
  139. }
  140.